package com.nhc.database.dbmodel;

import com.astrob.NavFrameSDK;
import com.astrob.model.GeoHash;
import com.astrob.model.LonLat;
import com.astrob.util.Utils;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;
import org.greenrobot.greendao.annotation.Transient;

/**
1. 定位精度 < 50米
2. 时间已矫正
3. 速度 >= 1米/秒
无记录点，都统计到停止时间里
 */

@Entity
public class TrackPoint {

    @Id(autoincrement = true)
    private Long id;
    private double longitude = 0;//经度
    private double latitude = 0;//纬度
    private double altitude = 0;//海拔高度
    private double speed = 0;//速度 米／秒 => *3.6 公里/小时
    private double dir = 0;//方向
    private double accuracy = 0;//精度 米
    private long datetime = 0; //时间
    private Long waytrail_id = 0L;//初始化时需删除非航迹点

    private String note = "";//备用 json

    @Index
    private String geohash = "";

    @Transient
    private LonLat ll_gcj = new LonLat(0, 0);//火星坐标系 (GCJ-02)

    public LonLat getLL_gcj() {
        if (ll_gcj.GetLon() == 0) {
            ll_gcj = Utils.wgs84togcj02(longitude, latitude);
        }
        return ll_gcj;
    }

    //获取指定长度的Geohash
    public String getGeohash(int len) {
        if (this.geohash.length() < 10) {
            GeoHash g = new GeoHash(new LonLat(longitude, latitude));
            g.sethashLength(10);//精确到1米
            this.geohash = g.getGeoHashBase32();
        }

        if (len < 0 || len >= 10) {
            len = 10;
        }

        String strGeohash = this.geohash.substring(0, len);
        return strGeohash;
    }

    @Generated(hash = 546431815)
    public TrackPoint() {
    }

    @Generated(hash = 1953905041)
    public TrackPoint(Long id, double longitude, double latitude, double altitude,
            double speed, double dir, double accuracy, long datetime,
            Long waytrail_id, String note, String geohash) {
        this.id = id;
        this.longitude = longitude;
        this.latitude = latitude;
        this.altitude = altitude;
        this.speed = speed;
        this.dir = dir;
        this.accuracy = accuracy;
        this.datetime = datetime;
        this.waytrail_id = waytrail_id;
        this.note = note;
        this.geohash = geohash;
    }

    public LonLat getLL() {
        return new LonLat(longitude, latitude);
    }

    public void setLL(LonLat ll) {
        if (ll != null) {
            longitude = ll.GetLon();
            latitude = ll.GetLat();

//            GeoHash g = new GeoHash(latitude, longitude);
//            g.sethashLength(10);//精确到1米
//            this.geohash = g.getGeoHashBase32();
        }
    }

    public void setLL(double llon, double llat) {
        longitude = llon;
        latitude = llat;

//        GeoHash g = new GeoHash(latitude, longitude);
//        g.sethashLength(10);//精确到1米
//        this.geohash = g.getGeoHashBase32();
    }

    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public double getLongitude() {
        return this.longitude;
    }
    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }
    public double getLatitude() {
        return this.latitude;
    }
    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }
    public double getAltitude() {
        return this.altitude;
    }
    public void setAltitude(double altitude) {
        this.altitude = altitude;
    }
    public double getSpeed() {
        return this.speed;
    }
    public void setSpeed(double speed) {
        this.speed = speed;
    }
    public double getDir() {
        return this.dir;
    }
    public void setDir(double dir) {
        this.dir = dir;
    }
    public double getAccuracy() {
        return this.accuracy;
    }
    public void setAccuracy(double accuracy) {
        this.accuracy = accuracy;
    }
    public long getDatetime() {
        return this.datetime;
    }
    public void setDatetime(long datetime) {
        this.datetime = datetime;
    }
    public Long getWaytrail_id() {
        return this.waytrail_id;
    }
    public void setWaytrail_id(Long waytrail_id) {
        this.waytrail_id = waytrail_id;
    }
    public String getGeohash() {
        return this.geohash;
    }
    public void setGeohash(String geohash) {
        this.geohash = geohash;
    }

    public String getNote() {
        return this.note;
    }

    public void setNote(String note) {
        this.note = note;
    }




}
